import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { getZzCoordinateData } from '@gis/lib/api';

const typeCodeEnum = {
  '3_01': 'dzz',
  '3_02': 'jwh',
  '3_03': 'wy',
  ldz: 'ldz',
  dyz: 'dyz',
  '3_04': 'ldz',
  '3_05': 'sjlm',
  '3_06': 'hyxh',
  '3_07': 'xqtt',
  dzz: 'dzz',
  wy: 'wy',
  D0063_2: 'jjzz',
  D0063_3: 'whzz',
  D0063_6: 'hyxh',
  D0063_7: 'xqtt',
  D0063_8: 'qtshzz',
};

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = typeCodeEnum[data.type_code];
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  onClick(e) {
    // console.log(e);
  }
}

export default class Zz extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      type: 3,
      dType: 'zz',
      area_code: area_code,
    };
    const data = await handleCommonRes(getZzCoordinateData, params);
    return data.map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
